package com.jerry.mingxing.ui.categroycategroy;

import android.os.Handler;

import com.jerry.mingxing.bean.CategroyBean;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/8/30.
 */
public class CategroyCategroyPresenter implements CategroyCategroyContract.Presenter {
    private CategroyCategroyContract.Mode mode;
    private CategroyCategroyContract.View view;
    public CategroyCategroyPresenter(CategroyCategroyContract.View view){
        this.view=view;
        this.mode=new CategroyCategroyMode();
    }

    @Override
    public void getData() {
        mode.loadCategroyCategroy(new Callback<CategroyBean>() {
            @Override
            public void onResponse(Call<CategroyBean> call, Response<CategroyBean> response) {
                if (response.isSuccessful()){
                    final CategroyBean body = response.body();
                    Handler handler=new Handler();
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            view.onResponse(body);
                        }
                    });

                }
            }

            @Override
            public void onFailure(Call<CategroyBean> call, Throwable t) {

                Handler handler=new Handler();
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onFailure("加载失败");
                    }
                });
            }
        });
    }
}
